// pages/home/home-nav/personal-overview/bpl/abnormal-bpl/index.ts
import AbnormalBPLInfo from '../../../../../../stores/AbnormalBPLInfo'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentStatus: 'all',
    allClass: 'status-active',
    normalClass: 'status-normal',
    lowClass: 'status-normal',
    lightClass: 'status-normal',
    middleClass: 'status-normal',
    highClass: 'status-normal',
    abnormalBPLs: <AbnormalBplInfo[]>[{
      riskLevel: '重度',
      uploadTime: '2024-05-19 17:18:00',
      systolic: 140,
      diastolic: 90,
      class: '',
    }, {
      riskLevel: '轻度',
      uploadTime: '2024-05-19 17:18:00',
      systolic: 140,
        diastolic: 90,
        class: '',
    }, {
      riskLevel: '中度',
      uploadTime: '2024-05-19 17:18:00',
      systolic: 140,
        diastolic: 90,
        class: '',
    }, {
      riskLevel: '重度',
      uploadTime: '2024-05-19 17:18:01',
      systolic: 140,
        diastolic: 90,
        class: '',
    }],
  },

  changeStatus(e: any) {
    if (e.currentTarget.dataset.status !== this.data.currentStatus) {
      console.log('需要切换页面');
      if (this.data.currentStatus === 'all') {
        this.setData({ allClass: 'status-normal' });
      }
      else if (this.data.currentStatus === '重度') {
        this.setData({ highClass: 'status-normal' });
      }
      else if (this.data.currentStatus === '中度') {
        this.setData({ middleClass: 'status-normal' });
      }
      else if (this.data.currentStatus === '轻度') {
        this.setData({ lightClass: 'status-normal' });
      }
      else if (this.data.currentStatus === '正常高值') {
        this.setData({ normalClass: 'status-normal' });
      }
      else {
        this.setData({ lowClass: 'status-normal' });
      }
      this.setData({ currentStatus: e.currentTarget.dataset.status })
      if (this.data.currentStatus === 'all') {
        this.setData({ allClass: 'status-active' });
        console.log('现在是全部');
      }
      else if (this.data.currentStatus === '重度') {
        this.setData({ highClass: 'status-active' });
        console.log('现在是重度');
      }
      else if (this.data.currentStatus === '中度') {
        this.setData({ middleClass: 'status-active' });
        console.log('现在是中度');
      }
      else if (this.data.currentStatus === '轻度') {
        this.setData({ lightClass: 'status-active' });
        console.log('现在是轻度');
      }
      else if (this.data.currentStatus === '正常高值') {
        this.setData({ normalClass: 'status-active' });
        console.log('现在是正常高值');
      }
      else {
        this.setData({ lowClass: 'status-active' });
        console.log('现在是偏低');
      }
    }
    else {
      console.log('不需要切换页面');
    }
  },

  decideClass: function(riskLevel) {
    switch (riskLevel) {
      case '重度':
        return 'risk-level-high';
      case '中度':
        return 'risk-level-middle';
      case '轻度':
        return 'risk-level-light';
      case '正常高值':
        return 'risk-level-normal';
      case '偏低':
        return 'risk-level-low';
      default:
        return 'black';
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.updateAbnormalBPLs();
  },

  updateAbnormalBPLs() {
    console.log('获取到的记录是', AbnormalBPLInfo.data);
    this.setData({
      abnormalBPLs: AbnormalBPLInfo.data
    })
    console.log('页面现在的记录是', this.data.abnormalBPLs);
    const updatedBPLs = this.data.abnormalBPLs.map(bpl => ({
      ...bpl,
      class: this.decideClass(bpl.riskLevel)
    }));
    this.setData({ abnormalBPLs: updatedBPLs });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})